<%@page import="com.dao.SqlOfUser"%>
<%@page import="com.servlet.M2"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="hyl.core.db.MyDB"%>
<%@page import="hyl.core.MyFun"%>
<%@page import="com.servlet.My"%>
<%@page import="hyl.ext.base.MySession"%>
<%@page import="java.io.PrintWriter"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
PrintWriter shuchu = response.getWriter();
	MySession tk = My.getSession(request,response);
	
	String 用户姓名 = request.getParameter("ualias");
	String imei = request.getParameter("imei");
	String oid = request.getParameter("oid");
	String uphone = request.getParameter("uphone");
	MyDB db = My.getDB1();
	String sql = "select * from device where t0=? and uid is not null";
	Object[] param = {imei};
	List<Map<String,Object>> list = db.queryList(sql, param);
	if(list.size()>0){
		shuchu.print("error");
		return;
	}
	
	/* sql = "select * from user where uphone = ?";
	Object[] ppa = {uphone};
	List<Map<String,Object>> list2 = db.queryList(sql, ppa);
	if(list2.size()>0){
		shuchu.print("error2");
		shuchu.flush();
		shuchu.close();
		return;
	} */
	
	MyDB cdb = My.getCommitDB1();
	sql = "insert into user(uname,ualias,roleid,istate,ctime,upass,uphone)values(?,?,?,?,now(),'96e79218965eb72c92a549dd5a330112',?)";
	Object[] params = {SqlOfUser.get_随机账号(),用户姓名,M2.ROLE_学生,M2.ROLE_学生,uphone};
	long id = cdb.executeUpdate(sql, params);
	
	sql = "insert into user_conf(id)values(?)";
	Object[] param2= {id};
	cdb.executeUpdate(sql, param2);
	
	sql = "insert into user_ext(id)values(?)";
	Object[] param3 = {id};
	cdb.executeUpdate(sql, param3);
	
	sql = "insert into org_user (oid,uid,itype)values(?,?,?)";
	Object[] param4 = {oid,id,0};
	cdb.executeUpdate(sql, param4);
	
	sql = "update device set uid=? where t0=?";
	Object[] param5 = {id,imei};
	cdb.executeUpdate(sql, param5);
	
	cdb.commit();
	shuchu.print("success");
%>